<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
?>
<p><a href="../">&lt;&lt; Back to Main Portal</a></p>
<h1>Courses</h1>
<p><b>Please select a subject to view courses for:</b></p>

<?php

//counting variable
$i = 0;

//select statement
$query="SELECT * FROM course_subjects";
$result=mysql_query($query);

//close
mysql_close();

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);


//start table
echo "<table class=\"postSchedule\">";
	
	//create table row with column ID's
	echo "<tr>";
		echo "<td><b>Subject</b></td>";
		echo "<td><b>Abbreviation</b></td>";
		echo "<td></td>";
	echo "</tr>";

//loop to walk through and print to screen all entries in course_subjects table
$row_count=0;
while ($i < $num_rows) 
{
	$row_count++;
	//store each subject name and abbreviation in a scalar
	$subject_id=mysql_result($result,$i,"id");
	$subject_title=mysql_result($result,$i,"subject_title");
	$abbreviation=mysql_result($result,$i,"abbreviation");
	
	//generate table row for each subject on each iteration of the loop
	echo "<tr";
	if (($row_count%2) != 0) echo " class=\"zebra_stripe\"";
	echo ">";
		echo "<td>$subject_title</td>";		//subject name cell
		echo "<td style='text-align: center'>$abbreviation</td>";		//subject abbreviation cell
		
		echo "<td>";		//cell containing form for update courses link/button
			echo "<a href='courses.php?id=$subject_id'>View Courses</a>";
		echo "</td>";
	echo "</tr>";
		
	//increment counting variable
	$i++;
}

//end table tag
echo "</table>";


?>



<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>